<template>
	<view class="user">
		<view class="top">
			<image src="../../static/images/history.png" mode="aspectFill"></image>
			<text>浏览历史</text>
		</view>
		<view class="content">
			<view class="row" v-for="item in historyArr">
				<newsbox :item="item" @click.native="goDetail(item)"></newsbox>
			</view>
		</view>
		
		<view class="nohistory" v-if="!historyArr">
			<image src="../../static/images/no-history.png" mode="widthFix"></image>
			<view class="text">暂无浏览记录</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//初始化历史记录
				historyArr:[]
			};
		},
		//生命周期函数，页面显示是触发
		onShow(){
			this.getHistroyData()
		},
		//事件方法
		methods:{
			//点击新闻，跳转到新闻详情页
			goDetail(item){
				uni.navigateTo({
					url:`/pages/detail/detail?cid=${item.classid}&id=${item.id}`
				})
			},
			//获取历史浏览记录
			getHistroyData(){
				//从缓存中读取浏览记录
				this.historyArr = uni.getStorageSync('historyArr')
			}
		}
	}
</script>

<style lang="scss">
.user{
	//顶部样式
	.top{
		padding: 50rpx;
		background: #f8f8f8;
		color:#555;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		image{
			width: 150rpx;
			height: 150rpx;
		}
		text{
			font-size: 38rpx;
			padding-top: 20rpx;
		}
	}
	//内容容器样式
	.content{
		padding: 30rpx;
		.row{
			border-bottom: 1rpx dotted #efefef;
			padding: 20rpx 0;
		}
	}
	//没有浏览记录样式
	.nohistory{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		image{
			width: 400rpx;
		}
		.text{
			font-size: 26rpx;
			color: #888;
		}
	}
}	

</style>
